using System;
using System.IO;

namespace LiJ.Http.Mos
{
	public struct FileParameter
	{
		/// <summary>
		/// 参数名称
		/// </summary>
		public string Name;

		/// <summary>
		/// 读写操作流
		///  返回的是写入的字节流长度
		/// </summary>
		public Action<Stream> Writer;

		/// <summary>
		/// 文件名称
		/// </summary>
		public string FileName;

		/// <summary>
		/// 文件类型
		/// </summary>
		public string ContentType;

		/// <summary>
		/// 构造函数
		/// </summary>
		/// <param name="name">参数的名称</param>
		/// <param name="fileStream">调用方会自动释放</param>
		/// <param name="filename"></param>
		/// <param name="contentType"></param>
		public FileParameter(string name, Stream fileStream, string filename, string contentType)
		{
            Writer = delegate(Stream s)
			{
				var array = new byte[1024];
				using (fileStream)
				{
					var num = 0;
					while ((num = fileStream.Read(array, 0, array.Length)) != 0)
					{
						s.Write(array, 0, num);
					}
				}
			};
			FileName = filename;
			ContentType = contentType;
			Name = name;
		}
	}
}
